# 案例三 英雄砍人

# 英雄类
import random


class Hero:
    name = '莫甘娜'
    hp = 100

    def __init__(self, name, hp):
        self.name = name
        self.hp = hp
        self.skills = []

    def isDead(self):
        return self.hp <= 0


# 技能类
class Skill:
    name = "绝望恐吓"
    damage = 10

    def __init__(self, name, damage):
        self.name = name
        self.damage = damage

    def attack(self, hero):
        hero.hp = hero.hp - self.damage
        print("%s攻击了%s,%s血量此时为%s" % (self.name, hero.name, hero.name, hero.hp))
        return hero.hp > 0


if __name__ == '__main__':
    print("开始英雄互砍")
    # 搞两个英雄
    lb = Hero('李白', 100)
    hx = Hero('韩信', 100)
    # 加技能
    lb.skills.append(Skill('将敬酒', 10))
    lb.skills.append(Skill('杯莫停', 11))
    lb.skills.append(Skill('青莲剑歌', 20))
    lb.skills.append(Skill('黄河天上来', 50))
    hx.skills.append(Skill('胯下直入', 15))
    hx.skills.append(Skill('单刀赴会', 15))
    hx.skills.append(Skill('英勇反击', 15))
    hx.skills.append(Skill('一个顶俩', 50))
    # 互砍开始
    while True:
        if lb.isDead() or hx.isDead():
            print("游戏结束。。。。")
            break
        lbSkill = lb.skills[random.randint(0, 3)]
        lbSkill.attack(hx)
        hxSkill = hx.skills[random.randint(0, 3)]
        hxSkill.attack(lb)
